home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
me_cd25.zip
/
MUTT2.ZIP
/
SPELL.MUT
< prev
next >
Wrap
Lisp/Scheme
|
1992-11-09
|
5KB
|
163 lines
;; Spelling correction interface for Emacs.
;; Copyright (C) 1985 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY. No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing. Refer to the GNU Emacs General Public
;; License for full details.
;; Everyone is granted permission to copy, modify and redistribute
;; GNU Emacs, but only under the conditions described in the
;; GNU Emacs General Public License. A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities. It should be in a
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
;; Ported to Mutt2 4/92 C Durland
;; Check spelling of every word in the buffer.
;; For each incorrect word, you are asked for the correct spelling and then
;; put into a query-replace to fix some or all occurrences. If you do not
;; want to change a word, just give the same word as its "correct"
;; spelling; then the query replace is skipped.
(include me2.h)
(defun spell-region
{
(int point)
(point (create-mark))
(set-mark point)
(spell-check-region THE-DOT THE-MARK "region")
(goto-mark point)
})
(defun spell-buffer
{
(int mark1 mark2 point bag)
(point (create-mark))(mark1 (create-mark))(mark2 (create-mark))
(set-mark point)
(beginning-of-buffer)(set-mark mark1)
(end-of-buffer) (set-mark mark2)
(spell-check-region mark1 mark2 "buffer")
(goto-mark point)
})
;; Check spelling of word at or before point.
;; If it is not correct, ask user for the correct spelling and
;; query-replace the entire buffer to substitute it.
(defun spell-word
{
(int mark1 mark2 point bag)
(point (create-mark))(mark1 (create-mark))(mark2 (create-mark))
(bag (create-bag))
(set-mark point)
; (if (not (looking-at '\<')) (previous-word))
(if (!= 1 (current-column)) ;; !!! bug work around
{
(previous-character)
(if (not (looking-at '.\<'))
{ (next-character)(previous-word) }
(next-character))
})
(set-mark mark1)
(next-word)(set-mark mark2)
(append-to-bag bag APPEND-REGION mark1 mark2)
(spell-check-region mark1 mark2 (concat "\"" (bag-to-string bag) "\""))
(goto-mark point)
})
;; Like spell-buffer but applies only to region.
;; From program, applies from START to END.
;; Notes:
;; Spell is case sensitive. The same (misspelled) word with different
;; case will be rejected twice.
;; !!! need case matching qr
(defun spell-check-region (int mark1 mark2) (string description) HIDDEN
{
(int buffer curbuf bag case-fold-state)
(string word newword)
(msg "Checking spelling of " description "...")
(case-fold-state (case-fold-search))(case-fold-search 0)
(curbuf (current-buffer))
(bag (create-bag))
(buffer (create-buffer "*temp*"))
(append-to-bag bag APPEND-REGION mark1 mark2)
(append-to-bag bag APPEND-TEXT "^J")
(current-buffer buffer)
(OS-filter "spell" bag -1 TRUE) ;; generate a list of bad words
(update)
(goto-line 1)
(msg "Checking spelling of " description "... "
(if (EoB) "correct" "not correct"))
; (case-fold-search t)
; (case-replace t)
(while (not (EoB))
{
(looking-at '.+')
(word (get-matched '&'))
(ask-user)(newword (ask "Replacement for " word ": "))
(if (== "-" newword) { (forward-line -1)(continue) })
(if (and (!= newword "") (!= word newword))
{
(current-buffer curbuf) (beginning-of-buffer)
(re-query-replace (concat '\<' word '\>') newword)
(current-buffer buffer)
})
(forward-line 1)
})
(current-buffer curbuf)
(case-fold-search case-fold-state)
})
;; Check spelling of string supplied as argument.
(defun spell-string ; (string s)
{
(int bag1 bag2)
(string s)
(s (ask "Spell string: "))
(bag1 (create-bag))
(bag2 (create-bag))
(append-to-bag bag1 APPEND-TEXT s)
(append-to-bag bag1 APPEND-TEXT "^J")
(OS-filter "spell" bag1 bag2)
(update)
(msg "\"" s "\" is "
(if (== 0 (length-of (bag-to-string bag2))) "correct." "incorrect."))
(free-bag bag1 bag2)
})